package com.wz.device.controller;


import com.wz.device.entity.BasRoadway;
import com.wz.device.service.BasRoadwayService;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.framework.web.page.TableDataInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author qiqi
 * @since 2021-10-22
 */
@Controller
@RequestMapping("/device/basRoadway")
public class BasRoadwayController extends BaseController {

    private String prefix = "device/basRoadway";

    @Autowired
    private BasRoadwayService basRoadwayService;



//    @RequiresPermissions("device:basRoadway:view")
    @GetMapping()
    public String user() {
        return prefix + "/basRoadway";
    }

    /**
     * 设备巷道信息列表
     * @param basRoadway
     * @return
     */
//    @RequiresPermissions("device:basRoadway:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasRoadway basRoadway){
        startPage();
        List<BasRoadway> list = basRoadwayService.selectBasRoadwayList(basRoadway);
        return getDataTable(list);
    }
//    @RequiresPermissions("device:basRoadway:list")
    @PostMapping("/list1")
    @ResponseBody
    public TableDataInfo list1(BasRoadway basRoadway){
        startPage();
        basRoadway.setIn_locked("N");
        List<BasRoadway> list = basRoadwayService.selectBasRoadwayList(basRoadway);
        return getDataTable(list);
    }

    /**
     * 新增设备巷道信息
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        return prefix + "/add";
    }

    /**
     * 设备巷道增加
     * @param basRoadway
     * @return
     */
    @RequiresPermissions("device:basRoadway:add")
    @Log(title = "设备巷道管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated BasRoadway basRoadway)
    {
        return toAjax(basRoadwayService.insertBasRoadway(basRoadway));
    }

    /**
     * 修改设备巷道信息
     */
    @RequiresPermissions("device:basRoadway:edit")
    @GetMapping("/edit/{device_id}")
    public String edit(@PathVariable("device_id") String device_id, ModelMap mmap)
    {
        mmap.put("basRoadway", basRoadwayService.selectBasRoadway(device_id));
        return prefix + "/edit";
    }

    /**
     * 修改保存设备巷道信息
     */
    @RequiresPermissions("device:basRoadway:edit")
    @Log(title = "设备巷道管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated BasRoadway basRoadway)
    {
        return toAjax(basRoadwayService.updateBasRoadway(basRoadway));

    }


    @RequiresPermissions("device:basRoadway:remove")
    @Log(title = "设备巷道管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {

        return toAjax(basRoadwayService.deleteBasRoadwayByIds(ids));
    }

    /**
     * 设备巷道是否锁定修改
     */
    @Log(title = "设备巷道管理", businessType = BusinessType.UPDATE)
    @RequiresPermissions("device:basRoadway:edit")
    @PostMapping("/changeLocked")
    @ResponseBody
    public AjaxResult changeLocked(BasRoadway basRoadway)
    {
        return toAjax(basRoadwayService.changeLocked(basRoadway));
    }


}
